<?php

/**
 * KTDCharacter form.
 *
 * @package    s-test
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class KTDCharacterForm extends BaseKTDCharacterForm
{
  public function configure()
  {
    $this->disableLocalCSRFProtection();

    $this->setWidgets(array(
        'pseudo' => new sfWidgetFormInputText(array("label"=>"Pseudonyme")),
        'hide_player' => new sfWidgetFormInputCheckbox(array("label"=> "Personnage anonyme", 'default'=> 0))
    ));
    $this->setValidators(array(
        'pseudo'    =>  new sfValidatorString(array('required'  =>  true), array("required"=>"Requis")),
        'hide_player'   => new sfValidatorBoolean()
    ));
    if($this->isNew())
     $this->embedForm('ktd_character_fiche', new KTDCharacterFicheForm());

    $this->widgetSchema->setNameFormat("ktd_character[%s]");

  }
  public function updateObject($values = null){
      parent::updateObject($values);
      
      if($this->isNew()){          
          $values = $this->getValues();
          $fiche = new KTDCharacterFiche();
          $fiche->fromArray($values['ktd_character_fiche']);
          $fiche->setKTDCharacter($this->object);

          $this->embeddedForms["ktd_character_fiche"] = new KTDCharacterFicheForm($fiche);
      }
      return $this->object;
  }
  public function save($conn = null){
      $character = parent::save($conn);
      $character->getKTDPlayer()->setActualCharacterId($character->getId());
      $character->save();
      return $character;
  }
}
